<template>
  <div id="login">
    <h1>登录页面</h1>
    <form>
      邮箱：
      <input type="text" name="email" v-model="email">
      密码：
      <input type="text" name="password" v-model="password">
    </form>
    <button @click="doLogin">登录</button>
    <p v-if="error">用户名密码不正确</p>
  </div>
</template>

<script>
import auth from '../util/auth'

export default {
  name: "Login",
  data() {
    return {
      email:'focuxin@qq.com',
      password:'',
      error:false
    }
  },
  methods: {
    doLogin(){
      auth.login(this.email,this.password).then(res=>{
        if(res.code !== 200){
          this.error = true;
          console.log(res)
        }else {
          console.log(res)
          this.$router.replace(this.$route.query.redirect || '/');
        }
      }).catch(err=>{
        console.error(err)
        this.error = true
      })
    }
  }
}
</script>

<style scoped>

</style>